<template>
  <el-form :model="detailForm" ref="detailForm" :rules="rules"
           :class="isEdit?'':'formItem'" :label-position="labelPosition">
    <el-card class="box-card" shadow="never">
      <div slot="header" class="header-card">
        <span class="header-card-title">购置税信息</span>
      </div>

      <el-row :gutter="24">
        <el-col :span="8" v-if="isShow">
          <el-form-item label="预计开始日期:" prop="expectStartTime">
            <el-date-picker type="date" v-model="detailForm.expectStartTime" v-if="isEdit"
                            placeholder="请选择预计开始日期"
                            value-format='yyyy-MM-dd' style="width: 100%;">
            </el-date-picker>
            <span v-else>{{ detailForm.expectStartTime }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="isShow">
          <el-form-item label="预计结束日期:" prop="expectEndTime">
            <el-date-picker type="date" v-model="detailForm.expectEndTime" v-if="isEdit"
                            placeholder="请选择预计结束日期"
                            value-format='yyyy-MM-dd' style="width: 100%;">
            </el-date-picker>
            <span v-else>{{ detailForm.expectEndTime }}</span>
          </el-form-item>
        </el-col>
      </el-row>

    </el-card>
  </el-form>
</template>

<script>
import {effectDate} from "@/utils/libs/effectDate.js"
export default {
  name:'purchaseTable',
  model: {
    prop: 'detailForm',
    event: 'update:detailForm',
  },

  props: {
    detailForm: {
      type: Object,
      default: {},
    },
    state: {
      type: String,
      default: "",
    },
  },
  data() {
    var start = (rule, value, callback) => {
      let that = this
      effectDate(rule, value, callback,
          that.detailForm.expectStartTime,
          that.detailForm.expectEndTime,
          '预计开始日期',
          '预计结束日期'
      )
    };
    var end = (rule, value, callback) => {
      let that = this
      effectDate(rule, value, callback,
          that.detailForm.expectStartTime,
          that.detailForm.expectEndTime,
          '预计开始日期',
          '预计结束日期'
      )
    };
    return {
      isForm: true,
      isShow: true,
      rules: {
        expectStartTime: [{required: this.state === 'write', validator: start, trigger: 'change'}],
        expectEndTime: [{required: this.state === 'write', validator: end, trigger: 'change'}]
      }
    };
  },
  computed: {
    labelPosition() {
      if (this.isEdit) {
        return "top";
      } else {
        return "left";
      }
    },
    isEdit() {
      let bool;
      switch (this.state) {
        case "write":
          bool = true;
          break;
        case "disabled":
          bool = false;
          break;
        case "readonly":
          bool = false;
          break;
      }
      return bool
    },
  },
  watch: {
    detailForm: {
      handler(newVal, oldVal) {
      },
      immediate: true,
      deep: true
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    handleEffect() {
      return new Promise((resolve, reject) => {
        this.$refs.detailForm.validate((valid) => {
          if (valid) {
            resolve()
          } else {
            reject()
          }
        });
      })
    },
    valid() {
      return new Promise((resolve) => {
        this.$refs.detailForm.validate((valid) => {
          resolve(valid);
        });
      })
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/styles/cwgd/formScss.scss";
</style>


